﻿
@using System.Collections.Generic
@using MrCMS.Models
@using MrCMS.Web.Areas.Admin.Models
@model MrCMS.Web.Areas.Admin.Models.AdminTree
@if (Model.IsRootRequest)
{
    <ul>
        <li class="jstree-open" id="@Model.RootContoller" data-can-add-child="True" data-sortable="True" data-haschildren="True" data-jstree='{"icon":"glyphicon glyphicon-certificate"}' data-controller="@Model.RootContoller">
            <a href="#">@Resource("Root")</a>
            @RenderChildren(Model.Nodes)
        </li>
    </ul>
}
else
{
    @RenderChildren(Model.Nodes)
}

@helper RenderChildren(List<AdminTreeNode> Model)
{
    <ul>
        @foreach (AdminTreeNode node in Model)
        {
            var cssClass = "";
            if (!node.IsPublished)
            {
                cssClass = "orange";
            }
            else if (!node.RevealInNavigation)
            {
                cssClass = "grey";
            }
            <li id="@node.Id" data-id="@node.Id" data-parent-id="@node.ParentId" 
                data-sortable="@node.Sortable" data-can-add-child="@node.CanAddChild"
                data-candelete="@(!node.HasChildren)" data-type="@node.Type" 
                data-controller="@node.NodeType" class="@(node.HasChildren ? "jstree-closed" : "")"
                data-jstree='{"icon":"@node.IconClass"}'>
                <a href="@node.Url" class="@cssClass">@node.Name</a>
            </li>

            //}
        }
    </ul>
}

